package cn.wolfcode.shop.cloud.web.advice;

import cn.wolfcode.shop.cloud.common.CommonExceptionAdvice;
import cn.wolfcode.shop.cloud.common.Result;
import cn.wolfcode.shop.cloud.msg.MemberCodeMsg;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@ControllerAdvice
public class UserControllerAdcice extends CommonExceptionAdvice {
    @ExceptionHandler(BindException.class)
    @ResponseBody
    public Result handlerMemberExp(BindException ex){
        String message = ex.getAllErrors().get(0).getDefaultMessage();
        MemberCodeMsg pararmError =  MemberCodeMsg.PARARM_ERROR;
        return Result.error(pararmError.filterArg(message));
    }
}
